//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    indexCurrent:null,
    videlList:'',//视频列表
    reachbottom:true,//返回顶部按钮
    bnrUrl: [{//轮播图
        "url": "https://wechat-applets.oss-cn-chengdu.aliyuncs.com/images/Shuffling_figure/1.jpg"
    },{
        "url": "https://wechat-applets.oss-cn-chengdu.aliyuncs.com/images/Shuffling_figure/2.jpg"
    },{
        "url": "https://wechat-applets.oss-cn-chengdu.aliyuncs.com/images/Shuffling_figure/3.jpg"
    }],
    // video:[
    //   {
    //   id:'001',
    //   title:"短视屏",
    //   videoUrl:{
    //       first: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/short-video/1.mp4',
    //       second: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/short-video/2.mp4',
    //       third: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/short-video/3.mp4'
    //   },
    //   videoImg: [{
    //     first: '',
    //     second: '',
    //     third: ''
    //   }]
    // },
    // {
    //   id:'002',
    //   title:"公益广告",
    //   image:'',
    //   videoUrl:{
    //       first: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/public-service-ads/1.mp4',
    //       second: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/public-service-ads/2.mp4',
    //       third: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/public-service-ads/3.mp4'
    //   },
    //   videoImg: [{
    //     first: '',
    //     second: '',
    //     third: ''
    //   }]
    // },
    // {
    //   id:'003',
    //   title:"vlog",
    //   image:'',
    //   videoUrl:{
    //       first: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/vlog/1.mp4',
    //       second: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/vlog/2.mp4',
    //       third: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/videos/vlog/3.mp4'
    //   },
    //   videoImg: [{
    //     first: '',
    //     second: '',
    //     third: ''
    //   }]
    // },
     //]
  },

  onLoad:function(res){
    var that=this;
    var videlList = this.data.videlList
    that.setData({
      reachbottom: false
    })

    //网络请求
    wx.request({
      url: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/json/case.json',
      method:'GET',
      header:{
        'content-type': 'application/json'
      },
      success: function (requestSuccess){
        //console.log(requestSuccess)//测试
      }, fail: function (failSuccess){
        //console.log(failSuccess)//测试
        wx.showModal({
          content: '网络开了小差，是否刷新？',
          success(res) {
            if (res.confirm) {
              //页面刷新
              const pages = getCurrentPages()
              const perpage = pages[pages.length - 1]
              perpage.onLoad()
            } else if (res.cancel) {

            }
          }
        })
      }
    })
    wx.request({
      url: 'https://wechat-applets.oss-cn-chengdu.aliyuncs.com/json/videoList.json',
      method:"GET",
      header:{
        'content-type': 'application/json'
      },
      success:function(res){
        that.setData({
          videlList:res.data
        })
      },fail:function(res){

      }
    })
  },

  // 视频跳转
  goToVidel:function(res){
    var id = res.currentTarget.dataset.index;
    wx.navigateTo({
      url:'/pages/videos/videos?id='+id
    })
  },

  // 点击拨打电话
  callPhone: function (res) {
    wx.makePhoneCall({
      //success:function(res){
        phoneNumber: '15760163770'
      //},
    })
  },

  // 滚动条监听
  onPageScroll:function(res){
    if (res.scrollTop > 200){
      this.setData({ 
        reachbottom: true 
        })
    }else{
      this.setData({ 
        reachbottom: false
         })
    }
  },
  // 点击返回顶部
  go_top:function(res){
    if (wx.pageScrollTo){
      wx.pageScrollTo({
        scrollTop: 0,
        duration:600
      })
    }else{
      wx.showModal({
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。',
      })
    }
  }
})
